package priv.pront.code.national.acwing.base;

import java.util.Scanner;

public class A1224_交换瓶子 {

    static int n, cnt = 0;
    static boolean[] st;
    static int[] arr;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        st = new boolean[n + 1];
        arr = new int[n + 1];
        for(int i = 1; i <= n; i++) arr[i] = scanner.nextInt();

        // 查找位置已经确定的点；
        for(int i = 1; i <= n; i++){
            if(arr[i] == i) st[i] = true;
        }

        // 查找一次解决2个瓶子的点
        for(int i = 1; i <= n; i++){
            // 如果两个瓶子都没有确定
            if(!st[i] && !st[arr[i]] && arr[arr[i]] == i){
                st[i] = true;
                st[arr[i]] = true;
                swap(i, arr[i]);
                cnt++;
            }
        }

        for(int i = 1; i <= n; i++){
            if(st[i]) continue;
            while(i != arr[i]){
                swap(i, arr[i]);
                cnt++;
            }
            st[i] = true;
        }
        System.out.println(cnt);
    }

    private static void swap(int a, int b){
        int tmp = arr[a];
        arr[a] = arr[b];
        arr[b] = tmp;
    }
}
